/**
 * 2018年12月23日下午5:14:20
 * @author 谢进财
 */
package com.baihang.project.ds.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baihang.framework.controller.BaseController;
import com.baihang.framework.kit.JsonKit;
import com.baihang.project.ds.service.EmployeeService;

/**
 * 用户管理
 *
 */
@Controller
@RequestMapping("/employee")
public class EmployeeController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(EmployeeController.class);
	@Autowired
	private EmployeeService service;
	
	@RequestMapping
	public String index() {
		return "/project/ds/employee/index";
	}
	@ResponseBody
	@RequestMapping(value="/showAllMenus",produces="application/json;charset=UTF-8")
	public String showAllMenus() {
		String json = service.getMenuTree();
		System.err.println(json);
		return json.replace("null", "\"\"");
	}
	
	@ResponseBody
	@RequestMapping(value="/getEmployeeGrid",produces="application/json;charset=UTF-8")
	public String getEmployeeGrid() {
		String json = service.getEmployeeGrid();
		System.err.println(json);
		return json.replace("null", "\"\"");
	}
	
	@ResponseBody
	@RequestMapping(value="/checkEmployeeExist",produces="application/json;charset=UTF-8")
	public String checkEmployeeExist(String userName) {
		String result = "false";
		if(service.checkEmployeeExist(userName)) {
			result="true";
		}
	  return JsonKit.toSingleJson(result);
	}
	@ResponseBody
	@RequestMapping(value="/saveEmployee",produces="application/json;charset=UTF-8")
	public String saveEmployee(String userName,String realName) {
		String result = "false";
		if(service.saveEmployee(userName, realName)) {
			result="true";
		}
		return JsonKit.toSingleJson(result);
	}
	
	@ResponseBody
	@RequestMapping(value="/delEmployee",produces="application/json;charset=UTF-8")
	public String delEmployee(int id) {
		String result = "false";
		if(service.delEmployee(id)) {
			result="true";
		}
		return JsonKit.toSingleJson(result);
	}
	
	@ResponseBody
	@RequestMapping(value="/saveEmployeeMenu",produces="application/json;charset=UTF-8")
	public String saveEmployeeMenu(@RequestParam("T_Uid") String userName,@RequestParam("T_Name")String realName,int id,String menu) {
		String result = "false";
		if(service.saveEmployeeMenu(userName,realName,id,menu)) {
			result="true";
		}
		return JsonKit.toSingleJson(result);
	}
	
	@ResponseBody
	@RequestMapping(value="/changePassword",produces="application/json;charset=UTF-8")
	public String changePassword(@RequestParam("empid") int id,@RequestParam("T_newpwd")String pwd) {
		String result = "false";
		if(service.changePassword(id,pwd)) {
			result="true";
		}
		return JsonKit.toSingleJson(result);
	}
	
	
}
